package com.ruipengkj.component;

import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListModel;

public class JLabelJListComponent extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JList list;
	public JLabelJListComponent(String _label, Object[] _listValues)
	{
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		this.setOpaque(false);
		list = new JList(_listValues);
		this.add(new JLabel(_label));
		this.add(list);
	}
	
	public JList getList()
	{
		return list;
	}
	
	public void setSelected(Object _value)
	{
		ListModel m = list.getModel();
		for(int i = 0, c = m.getSize(); i < c; i ++)
		{
			Object o = m.getElementAt(i);
			if(o.equals(_value))
			{
				list.setSelectedIndex(i);
				break;
			}
		}
	}
}
